<?php

namespace Admin\Controller; //当前命名空间跟文件目录一样
use Common\Common\CommonController;  //继承公共控制器类，时刻检测管理员身份
class DumpController extends CommonController
{
	//回收商品
	public function add()
	{
		//检查管理员登录信息
		$this->checkAdmin();
		//获取回收的商品id
		$good_id = I('get.gi');
		$where = array('goods_id' => $good_id);
		//获取该商品的所有信息
		$modelGoods = D('goods');
		$goods_info = $modelGoods->where($where)->find();
		if ($goods_info) {
			$modelDump = M('dump');  //获取该回收站对象
			$modelDump->add($goods_info);  //将商品信息加入回收站
			if ($modelGoods->where($where)->delete())     //删除商品在商品表中的信息
			{
				$this->success("已将该商品添加到回收站", U("?m=admin&c=goods&a=index"));
				die;
			}
		}
		$this->error("回收商品失败！", U("?m=admin&c=goods&a=index"));
	}

	//显示回收的商品列表
	public function showList()
	{
		//检查管理员登录信息
		$this->checkAdmin();
		$model = M('dump');
		$dumpList = $model->select();
		$this->assign("goodsInfo", $dumpList);
		$this->display();
	}

	//彻底删除回收商品
	public function ddelete()
	{
		//检查管理员登录信息
		$this->checkAdmin();
		//接收回收商品称号
		$dump_id = I('dpi');
		$model = M('dump');
		if ($model->where(array("dump_id" => $dump_id))->delete()) {
			$this->success("已清除该商品信息！！", U('?m=admin&c=dump&a=showList'));
			die;
		}
	}

	//回收商品查询
	public function query()
	{
		//获取传递的商品名称信息
		$goodsName = I('goods_name');
		$where = array('goods_name' => array("like", '%' . $goodsName . '%')); //构建商品名称模糊查询条件
		$model = D('dump');   //实例化模型类对象	
		$goodsInfo = $model->where($where)->select();  //获取模糊查询商品信息
		$this->assign("goodsInfo", $goodsInfo);
		$this->display();
	}
}
